package com.macro.mall.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.SmsCoupon;
import com.macro.mall.service.UmsCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：MinxiaoHao
 * @Description:
 * @name：UmsCouponController
 * @Date：2024/10/23 16:08
 */
@RestController
@RequestMapping("/member/coupon")
public class UmsCouponController {
    @Autowired
    private UmsCouponService umsCouponService;

    /**
     * 查询优惠卷列表
     * @param id 商品id
     * @return 优惠卷列表
     */
    @GetMapping("/listByProduct/{id}")
    public CommonResult<List<SmsCoupon>> listByProduct(@PathVariable Long id) {
        List<SmsCoupon> list= umsCouponService.listByProduct(id);
        return CommonResult.success(list);
    }

    /**
     * 商品添加优惠卷
     * @param couponId 优惠卷id
     */
    @PostMapping("/add/{couponId}")
    public CommonResult add(@PathVariable Long couponId) {
        int count = umsCouponService.add(couponId);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

}
